﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Pg.BioMedics.SDR.Entities;

namespace Pg.BioMedics.SDR.Services.Algorithms
{
    internal class WeightingBinaryAlgorithm : IWeightingAlgorithm
    {
        #region IWeightingAlgorithm Members

        /// <summary>
        /// Calculates Q weight for the term t value within the query Q
        /// tokens set.
        /// </summary>
        /// <param name="t">Token</param>
        /// <param name="Q">List of tokens in the query</param>
        /// <returns>Weighting value</returns>
        public double CalculateQWeight(Token t, Token[] Q)
        {
            foreach (Token qToken in Q)
                if (qToken.Value == t.Value)
                    return 1.0d;

            return 0.0d;
        }

        /// <summary>
        /// Calculates D weight value for token t the document D
        /// </summary>
        /// <param name="t">Token term</param>
        /// <param name="D">Document tokens</param>
        /// <returns>Weighting value</returns>
        public double CalculateDWeight(Token t, Token[] D)
        {
            foreach (Token dToken in D)
                if (dToken.Value == t.Value)
                    return 1.0d;

            return 0.0d;
        }

        #endregion
    }
}
